package mipo.top.pet.controller;

import mipo.top.base.util.JsonResult;
import mipo.top.base.util.PageUtil;
import mipo.top.pet.Service.IProductDetailService;
import mipo.top.pet.domain.ProductDetail;
import mipo.top.pet.query.ProductDetailQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/productDetail")
public class ProductDetailController {

    @Autowired
    private IProductDetailService productDetailService;

    @GetMapping
    public List<ProductDetail> sad(){
        return productDetailService.findall();
    }

    @PutMapping
    public JsonResult su(@RequestBody ProductDetail productDetail){
        try {
            if(productDetail.getId()==null){
                productDetailService.save(productDetail);
            }else{
                productDetailService.update(productDetail);
            }
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("错误数据");
        }
    }

    @DeleteMapping("/{id}")
    public void adw(@PathVariable("id") Long id){
        productDetailService.remove(id);
    }
    @GetMapping("/{id}")
    public ProductDetail findone(@PathVariable("id") Long id){
      return productDetailService.findone(id);
    }

    @PostMapping
    public PageUtil<ProductDetail> asp(@RequestBody ProductDetailQuery productDetailQuery){
        return productDetailService.queryData(productDetailQuery);
    }
    @PatchMapping
    private void bacthDel(@RequestBody List<Long> ids){
        productDetailService.patchremove(ids);
    }
}
